package main

import (
	"fmt"
	"github.com/tjfoc/gmsm/sm2"
	"crypto/sha256"
	"math/big"
	"time"
)

func print_hex(in []byte, len int) {
	var i int
	for i = 0; i < len; i++ {
		fmt.Printf("%02X", in[i])
		/*		if i%4==3{
					fmt.Printf(" ")
				}*/
	}
	fmt.Println()
}
func test_sm2_by_TJ() {

	pri,_:=sm2.GenerateKey()
	msg := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
	hfunc := sha256.New()
	hfunc.Write(msg)
	hmac := hfunc.Sum(nil)
	var r, s *big.Int

	fmt.Println("sm2 by TJ:")
	fmt.Println("sm2 sign by TJ")

	//	fmt.Println(pri.Curve.Params().Gx.Bytes())
	t1:=time.Now()
	for i:=0;i<10000;i++{

		r,s,_=sm2.Sign(pri,hmac)
	}
	elspsed:=time.Since(t1)
	fmt.Println(elspsed)

	fmt.Println("sm2 verify by TJ")
	t1=time.Now()
	for i:=0;i<10000;i++{
		sm2.Verify(&pri.PublicKey,hmac,r,s)
	}
	elspsed=time.Since(t1)
	fmt.Println(elspsed)

}

func main() {

	test_sm2_by_TJ()

}